package com.inphase.doc.utils;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;

import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

public class FillFormat {
    public static String render(String template, Map<String, String> values) {
        if (values == null) {
            values = new HashMap<String, String>();
        }

        String answer = null;
        StringWriter writer = new StringWriter();
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile(new StringReader(template), template);
        mustache.execute(writer, values);
        writer.flush();
        answer = writer.getBuffer().toString();


        return answer;
    }
}
